/**
 * 汇总：
 * 1. 虽然task_delete的优先级较低，但是实际上却先被执行导致task01直接被删，原因未知；
 * 2. 空闲任务的看门狗未按时投喂会出现警报；
 */

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"

TaskHandle_t task01_handle;

void task01_fuction(void* argument){
    int cnt = 0;
    while(1){
        ESP_LOGI("task01", "%d\n",cnt++);
        if(cnt > 10){
            vTaskDelay(pdMS_TO_TICKS(500));
        }
    }
}

void task_delete_fuction(void* argument){
    vTaskDelay(pdMS_TO_TICKS(500));
    vTaskDelete(task01_handle);
    ESP_LOGI("task_delete", "task01 has been deleted");
    while(1){
        vTaskDelay(pdMS_TO_TICKS(500));
    }
}
void app_main(void)
{
    BaseType_t res1 = xTaskCreatePinnedToCore(&task01_fuction, "task01", 2048, NULL, configMAX_PRIORITIES-1, &task01_handle, APP_CPU_NUM);
    BaseType_t res2 = xTaskCreatePinnedToCore(&task_delete_fuction, "task_delete", 2048/2, NULL, 3, NULL, APP_CPU_NUM);

    if(res1 != pdPASS){
        ESP_LOGI("main", "Task Create Not Success\n");
    }
}
